cfgcjm Posted June 26, 2008 Share Posted June 26, 2008 Hi everyone, I'm trying to run this script (1st below) and it's running errorless but not populating the fields as it's supposed too but if i switch it around (2nd below) below it does work. It must be my syntax but i'm not sure what. How I want it to work and it doesn't now <?php session_start(); //Call dbconnection powerscript require_once "connect.php"; //Pull vars from get url $lastname = urldecode($_GET['param']); $firstname = urldecode($_GET['param2']); $sql = "SELECT * FROM records WHERE fname='$firstname' AND lname='$lastname'"; if ($r = mysql_query ($sql)) { $row = mysql_fetch_array ($r); $num = mysql_num_rows ($r); if ($num > 0) //If the Student Has an existing Record { $fname=$row['fname']; $lname=$row['lname']; $age = $row['age']; //echo back script echo '<script type="text/javascript"> document.getElementById("fname").value = $fname; document.getElementById("lname").value = $lname; document.getElementById("age").value = $age; </script>'; } } ?> How it does work <?php session_start(); //Call dbconnection powerscript require_once "connect.php"; //Pull vars from get url $lastname = urldecode($_GET['param']); $firstname = urldecode($_GET['param2']); $sql = "SELECT * FROM records WHERE fname='$firstname' AND lname='$lastname'"; if ($r = mysql_query ($sql)) { $row = mysql_fetch_array ($r); $num = mysql_num_rows ($r); if ($num > 0) //If the Student Has an existing Record { $fname=$row['fname']; $lname=$row['lname']; $age = $row['age']; //echo back script echo '<script type="text/javascript"> document.getElementById("fname").value = "Christopher"; document.getElementById("lname").value = "Miller"; document.getElementById("age").value = "17"; </script>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112013-php-echo-problem-with-no-error/ Share on other sites More sharing options...
Wolphie Posted June 26, 2008 Share Posted June 26, 2008 Put error_reporting("E_ALL"); at the top of your script and report back with the results. Quote Link to comment https://forums.phpfreaks.com/topic/112013-php-echo-problem-with-no-error/#findComment-574977 Share on other sites More sharing options...
ober Posted June 26, 2008 Share Posted June 26, 2008 Why are you dumping it out in a JavaScript tag? There are no actions in the JavaScript to call it. You can simply put those values right in the form elements if that is what you're trying to do. Other things you're doing wrong: 1) You're pulling the data out before you check to see if you have any results. That's backwards. 2) Replace: $fname=$row['fname']; $lname=$row['lname']; $age = $row['age']; with: extract($r); Quote Link to comment https://forums.phpfreaks.com/topic/112013-php-echo-problem-with-no-error/#findComment-574992 Share on other sites More sharing options...
kenrbnsn Posted June 26, 2008 Share Posted June 26, 2008 Variables enclosed in single quotes are not evaluated. Try this: <?php //echo back script echo '<script type="text/javascript"> document.getElementById("fname").value = ' . $fname . '; document.getElementById("lname").value = ' . $lname . '; document.getElementById("age").value = ' . $age .; </script>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/112013-php-echo-problem-with-no-error/#findComment-574993 Share on other sites More sharing options...
cfgcjm Posted June 26, 2008 Author Share Posted June 26, 2008 I added the error reporting and changed the echo script as ken prescribed and i'm still not getting the values in the fields and still no error. Below is my current script <?php session_start(); //Call dbconnection powerscript error_reporting("E_ALL"); require_once "connect.php"; //Pull vars from get url $lastname = urldecode($_GET['param']); $firstname = urldecode($_GET['param2']); $sql = "SELECT * FROM records WHERE fname='$firstname' AND lname='$lastname'"; if ($r = mysql_query ($sql)) { $row = mysql_fetch_array ($r); $num = mysql_num_rows ($r); if ($num > 0) //If the Student Has an existing Record { $fname=$row['fname']; $lname=$row['lname']; $age = $row['age']; //echo back script echo '<script type="text/javascript"> document.getElementById("fname").value = ' . $fname . '; document.getElementById("lname").value = ' . $lname . '; document.getElementById("age").value = ' . $age .'; </script>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112013-php-echo-problem-with-no-error/#findComment-575216 Share on other sites More sharing options...
cfgcjm Posted June 26, 2008 Author Share Posted June 26, 2008 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/112013-php-echo-problem-with-no-error/#findComment-575493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.