Newbie can't link variables from fetch to values

I am new to php. I know this is going to seem very dumb, but I cannot find a tutorial that details what I need to do with my script. I know there are other ways to do things in my script, but I am trying to walk before I run.

I have converted an html design to php and automated the unique user data from a Php file into the pages.

I don’t seem to be able to transfer by user_id from my table into the unique pages.

The unique webpages work perfectly from the php file I created, so, it is in my databse connection and fetching the data.

I have a id.php page that contains:

<?php $User_Id = "1"; ?>

I have a user_data.php page that contains:

<?php require("id.php"); $connect = mysql_connect("localhost", "root", "root"); if(!$connect){ my_sql_select_db("Contact Points",$connect); $query = "SELECT * FROM College WHERE User_Id='" . $User_Id . '"; $results = mysql_query($query); while($row = mysql_fetch_array($results)){ $row[User_Id] = $myUser_Id; $row[username] = $myUsername; $row[password] = $myPassword; $row[active] = $myActive; $row[First_Name] = $myFirst_Name; $row[Last_Name] = $myLast_Name; $row[Year_Grad] = $myYear_Grad; $row[School] = $mySchool; $row[Major] = $myMajor; $row[BIO_info] = $myBIO_info; $row[Home_Phone] = $myHome_Phone; $row[Home_Phone_Dial] = $myHome_Phone_Dial; $row[Cell_Phone] = $myCell_Phone; $row[Cell_Phone_Dial] = $myCell_Phone_Dial; $row[Street_Address] = $myStreet_Address; $row[Address_Line2] = $myAddress_Line2; $row[City] = $myCity; $row[State] = $myState; $row[Zip_Code] = $myZip_Code; $row[Country] = $myCountry; $row[Email] = $myEmail; } } else { die(mysql_error()); } ?>

I appreciate any help you can provide.

Sorry I read the posting procedure.

This is id.php:
[php]$User_Id = “1”;[/php]

This is user_id.php:
[php]<?php
require(“id.php”);
$connect = mysql_connect(“localhost”, “root”, “root”);
if(!$connect){
my_sql_select_db(“Contact Points”,$connect);
$query = “SELECT * FROM College WHERE User_Id=’” . $User_Id . '";
$results = mysql_query($query);
while($row = mysql_fetch_array($results)){
$row[User_Id] = $myUser_Id;
$row[username] = $myUsername;
$row[password] = $myPassword;
$row[active] = $myActive;
$row[First_Name] = $myFirst_Name;
$row[Last_Name] = $myLast_Name;
$row[Year_Grad] = $myYear_Grad;
$row[School] = $mySchool;
$row[Major] = $myMajor;
$row[BIO_info] = $myBIO_info;
$row[Home_Phone] = $myHome_Phone;
$row[Home_Phone_Dial] = $myHome_Phone_Dial;
$row[Cell_Phone] = $myCell_Phone;
$row[Cell_Phone_Dial] = $myCell_Phone_Dial;
$row[Street_Address] = $myStreet_Address;
$row[Address_Line2] = $myAddress_Line2;
$row[City] = $myCity;
$row[State] = $myState;
$row[Zip_Code] = $myZip_Code;
$row[Country] = $myCountry;
$row[Email] = $myEmail;

}

} else {
die(mysql_error());
}

?>[/php]

Read this to yourself…if connect is false or in other words
If connect does not work, then do everything below.
So if it doesn’t work you want to query the database? Change your condition:
[php]if($connect){[/php]

Pay more attention, the function is:
[php]mysql_select_db() [/php]

NOT
[php] my_sql_select_db()[/php]

your query string looks wrong
[php]$query = "SELECT * FROM College WHERE User_Id = ‘{$User_Id}’;[/php]

while should be if
[php]
if($row = mysql_fetch_array($results)){
[/php]

Do this to ALL of your array keys
[php]$row[‘User_Id’][/php]

you’re also assigning your vars wrong.
[php] $row[username] = $myUsername;[/php]

should be
[php] $myUsername = $row[‘username’];[/php]

Thanks so much!

I added more, refer above. :wink:

[php]$query = "SELECT * FROM College WHERE User_Id $query = "SELECT * FROM College WHERE User_Id = ‘{$User_Id}’;

[/php]

the “WHERE User_Id” is meant to be the select the row “User_Id” from the database table.

The = ‘{$User_Id}’; is mean to use the require file ID number of the user (for now).

I am getting a syntax error that I do not know how to resolve.

Thanks again!

whoa whoa whoa…
its suppose to be
[php]$query = "SELECT * FROM College WHERE User_Id = {$User_Id};
[/php]

you have
[php]$query = "SELECT * FROM College WHERE User_Id $query = "SELECT * FROM College WHERE User_Id = ‘{$User_Id}’;
[/php]

I still can’t make this work:

I get this reply from code checker:

PHP Syntax Check: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in your code on line 9
PHP Syntax Check: Errors parsing your code

[php]<?php
require(“id.php”);
$connect = mysql_connect(“localhost”, “root”, “root”);
if($connect){
mysql_select_db(“Contact Points”,$connect);
$query = "SELECT * FROM College WHERE User_Id = {$User_Id}’;
$results = mysql_query($query);
if($row = mysql_fetch_array($results)){
$myUser_Id = $row[‘User_Id’];
$myUsername = $row[‘username’];
$myPassword = $row[‘password’];
$myActive = $row[‘active’];
$myFirst_Name = $row[‘First_Name’];
$myLast_Name = $row[‘Last_Name’];
$myYear_Grad = $row[‘Year_Grad’];
$mySchool = $row[‘School’];
$myMajor = $row[‘Major’];
$myBIO_info = $row[‘BIO_info’];
$myHome_Phone = $row[‘Home_Phone’];
$myHome_Phone_Dial = $row[‘Home_Phone_Dial’];
$myCell_Phone = $row[‘Cell_Phone’];
$myCell_Phone_Dial = $row[‘Cell_Phone_Dial’];
$myStreet_Address = $row[‘Street_Address’];
$myAddress_Line2 = $row[‘Address_Line2’];
$myCity = $row[‘City’];
$myState = $row[‘State’];
$myZip_Code = $row[‘Zip_Code’];
$myCountry = $row[‘Country’];
$myEmail = $row[‘Email’];

}

} else {
die(mysql_error());
}

?>[/php]

[php] $query = “SELECT * FROM College WHERE User_Id = {$User_Id}”;[/php]

Spring,

Thank you so much for your help! I cannot tell you how appreciative and thankful I am for your help!

It worked great!

Sponsor our Newsletter | Privacy Policy | Terms of Service