need help with ereg function
Moderator: General Moderators
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
Insert a line right before...
and put....
And let me know what the output is.
Code: Select all
$result=mysql_query($query) or die ('ERROR : '. mysql_error());Code: Select all
echo $query;-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
Try...
Code: Select all
$insert_id_variable = mysql_insert_id();Code: Select all
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
here's the code:
Code: Select all
<?php
session_start();
// include function files for this application
require_once('bookmark_fns.php');
//create short variable names
$username = $HTTP_POST_VARS['username'];
$passwd = $HTTP_POST_VARS['passwd'];
if ($username && $passwd)
// they have just tried logging in
{
if (login($username, $passwd))
{
// if they are in the database register the user id
$HTTP_SESSION_VARS['valid_user'] = $username;
}
else
{
// unsuccessful login
do_html_header('Problem:');
echo 'You could not be logged in.
You must be logged in to view this page.';
do_html_url('login.php', 'Login');
do_html_footer();
exit;
}
}
$db_name = "database";
$table_name = "checkout";
$link_id = mysql_connect("localhost", "username", "password")
or die("Couldn't connect.");
$db = mysql_select_db($db_name, $link_id)
or die("Couldn't select database.");
mysql_query ("INSERT INTO $table_name (billfirstname, billlastname, billstreetaddr, billcity, billstate, billzipcode, billcountry, billcounty, email, phone, payment, creditnum, expire, questions, shipfirstname, shiplastname, shipstreetaddr, shipcity, shipstate, shipzipcode, shipcountry, shipcounty)
VALUES ('$billfirstname', '$billlastname', '$billstreetaddr', '$billcity', '$billstate', '$billzipcode', '$billcountry', '$billcounty', '$email', '$phone', '$payment', '$creditnum', '$expire', '$questions', '$shipfirstname', '$shiplastname', '$shipstreetaddr', '$shipcity', '$shipstate', '$shipzipcode', '$shipcountry', '$shipcounty')");
echo "$select<br>";
$host ="localhost";
$db_user="username";
$db_pass="password";
$database="database";
mysql_connect($host,$db_user,$db_pass);
mysql_select_db($database) or die ("Unable to select database");
echo "<center>Thank You For Shopping With Us!</center><br>";
echo "<center>";
check_valid_user();
echo "</center>";
echo "<br>";
echo "<center><a href='logout.php'>Click here to Logout</a></center>";
echo "<br>";
include("check.php");
echo "<br>";
echo "<strong>Your Billing and Shipping information!</strong>";
$query = "SELECT * FROM `$table_name` WHERE `id` = $id";
echo $query;
$result=mysql_query($query) or die ('ERROR : '. mysql_error());
$num=mysql_numrows($result);
echo "<br><br>";
echo "id variable";
$insert_id_variable = mysql_insert_id();
echo "<br>";
echo "the number of rows are: ";
echo $num;
if (!function_exists('datecheck'))
{
function datecheck($intext) {
$theresults = ereg("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $intext, $trashed);
if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
echo(""$intext" $isamatch<br>\n");
}
}
function phonecheck($intext) {
$theresults = ereg("([0-9]{3})-([0-9]{3})-([0-9]{4})", $intext, $trashed);
if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
echo(""$intext" $isamatch<br>\n");
}
function ccnumcheck($intext) {
$theresults = ereg("([0-9]{16})", $intext, $trashed);
if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
echo(""$intext" $isamatch<br>\n");
}
function emailcheck($intext) {
$theresults = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $intext, $trashed);
if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
echo(""$intext" $isamatch<br>\n");
}
$result = mysql_query($query, $link_id);
while($query_data = mysql_fetch_row($result)) {
echo "<table>";
echo "<tr>";
echo "<td>billfirstname</td>";
echo "<td>",$query_data[0],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>billlastname</td>";
echo "<td>",$query_data[1],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>billstreetaddr</td>";
echo "<td>",$query_data[2],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>billcity</td>";
echo "<td>",$query_data[3],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>billstate</td>";
echo "<td>",$query_data[4],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>billzipcode</td>";
echo "<td>",$query_data[5],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>billcountry</td>";
echo "<td>",$query_data[6],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>email<br>";
echo "</td>";
echo "<td>",emailcheck("$email"),"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>phone</td>";
echo "<td>",phonecheck("$phone"),"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>payment</td>";
echo "<td>",$query_data[10],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>creditnum</td>";
echo "<td>",ccnumcheck($creditnum),"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>expire</td>";
echo "<td>",datecheck($expire),"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>questions</td>";
echo "<td>",$query_data[13],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>shipfirstname</td>";
echo "<td>",$query_data[14],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>shiplastname</td>";
echo "<td>",$query_data[15],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>shipstreetaddr</td>";
echo "<td>",$query_data[16],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>shipcity</td>";
echo "<td>",$query_data[17],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>shipstate</td>";
echo "<td>",$query_data[18],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>shipzipcode</td>";
echo "<td>",$query_data[19],"</td>";
echo "</tr>";
echo "<tr>";
echo "<td>shipcountry</td>";
echo "<td>",$query_data[20],"</td>";
echo "</tr>";
echo "</table>";
if(isset($_COOKIE['cartId'])) {
echo "<center><strong>----- cookie is set ----- </strong></center>";
}
else {
echo "<center><strong>----- cookie is NOT set ----- </strong></center>";
}
}
?>Find this block of code...
And replace with....
Then remove....
Code: Select all
mysql_query ("INSERT INTO $table_name (billfirstname, billlastname, billstreetaddr, billcity, billstate, billzipcode, billcountry, billcounty, email, phone, payment, creditnum, expire, questions, shipfirstname, shiplastname, shipstreetaddr, shipcity, shipstate, shipzipcode, shipcountry, shipcounty)
VALUES ('$billfirstname', '$billlastname', '$billstreetaddr', '$billcity', '$billstate', '$billzipcode', '$billcountry', '$billcounty', '$email', '$phone', '$payment', '$creditnum', '$expire', '$questions', '$shipfirstname', '$shiplastname', '$shipstreetaddr', '$shipcity', '$shipstate', '$shipzipcode', '$shipcountry', '$shipcounty')");Code: Select all
mysql_query ("INSERT INTO $table_name (billfirstname, billlastname, billstreetaddr, billcity, billstate, billzipcode, billcountry, billcounty, email, phone, payment, creditnum, expire, questions, shipfirstname, shiplastname, shipstreetaddr, shipcity, shipstate, shipzipcode, shipcountry, shipcounty)
VALUES ('$billfirstname', '$billlastname', '$billstreetaddr', '$billcity', '$billstate', '$billzipcode', '$billcountry', '$billcounty', '$email', '$phone', '$payment', '$creditnum', '$expire', '$questions', '$shipfirstname', '$shiplastname', '$shipstreetaddr', '$shipcity', '$shipstate', '$shipzipcode', '$shipcountry', '$shipcounty')");
$id = mysql_query_id();Code: Select all
$insert_id_variable = mysql_insert_id();-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
Thats probably down to me consuming too much Guiness.
Change....
to...
If that doesn't work then try...
Change....
Code: Select all
$id = mysql_query_id();Code: Select all
$id = mysql_insert_id();Code: Select all
$id = mysql_insert_id($link_id);-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact: